<template>
    <van-pull-refresh 
        v-model="isLoading" 
        @refresh="onRefresh"
    >
        <van-list
            v-model="loading"
            :finished="finished"
            finished-text="没有更多了"
            @load="onLoad"
            :immediate-check="false"
        >
             <slot></slot>
        </van-list>
       
    </van-pull-refresh>
</template>


<script>
import {Toast} from "vant"
export default {
    data(){
        return {
            isLoading:false,
            loading:false,
            finished:false,  // 数据已经全部加载 
        }
    },
    props:{
        refreshdata:Function,
        loadmore:Function 
    },
    methods:{
        onRefresh(){
            
            setTimeout(() => {
                this.refreshdata(()=>{
                    Toast('刷新成功');
                    this.isLoading = false;
                    
                })
            }, 800);
        },
        onLoad(){
            setTimeout(() => {
                this.loadmore(
                    ()=>{
                        this.loading = false;
                        Toast("下拉加载成功")
                    },
                    ()=>{
                        // this.loading=true;
                        this.finished = true;
                        Toast("数据见底了...")
                    }
                )
            }, 300);
        }
    }
}
</script>